package com.ityedao.方法引用.静态和实例方法引用;

import java.util.Arrays;

public class ComparableTest {
    public static void main(String[] args) {
        Student[] students = new Student[4];
        students[0] = new Student("小花", 18, 168.5);
        students[1] = new Student("白月光", 45, 165.2);
        students[2] = new Student("逆魔王", 28, 188.9);
        students[3] = new Student("白骨精", 999, 172.6);

        // public static <T> void sort(T[] arr, Comparator<? super T> c) 对数组进行排序（支持自定义排序规则）
        // 参数一：需要进行排序的数组
        // 参数二：Comparator比较器对象（用来制定对象的比较规则）

        // 静态方法引用
//        Arrays.sort(students, (o1, o2) -> o1.getAge() - o2.getAge());
//        Arrays.sort(students,(o1, o2) -> CompareData.compareByAge(o1, o2));
//        Arrays.sort(students, CompareData::compareByAge);

        // 实例方法引用
        CompareData compare = new CompareData();
//        Arrays.sort(students, (o1, o2) -> compare.compareByAgeDesc(o1, o2));
        Arrays.sort(students, compare::compareByAgeDesc);

        System.out.println(Arrays.toString(students));
    }
}
